<?php
	/*
	file ini digunakan untuk mengontrol login apakah user telah sesuai prosedur masuk aplikasi
	*/
class c_group extends CI_Controller {

	function __construct(){
		parent::__construct();
		session_start();
		$this->load->model('m_group');
		if(!isset($_SESSION[SESSION_USERID])){
			redirect(base_url());
		}

	}//end Login

	function get_action(){
		$task = isset($_POST['task']) ? @$_POST['task'] : $_GET['task'];
		switch($task){
			case "list":
				$this->group_list();
			break;
			case "create":
				$this->group_create();
			break;
			case "update":
				$this->group_update();
			break;
			case "delete":
				$this->group_delete();
			break;
			case "search":
				$this->group_search();
			break;
			default:
				echo "{ failure : true }";
			break;
		}
	}

	function index(){
		$data["title"]="GROUP USER";
		$data["content"]=$this->load->view('admin/v_group_list',$data,TRUE);
		$this->load->view('admin/v_template',$data);
	}

	function group_load(){
		$this->load->view('admin/v_group_list');
	}

	function group_addedit(){
		$data = array();
		$id = $this->uri->segment(3);
		if($id != false){
			$data['dataDetail'] = $this->m_group->getDetail($id);
		}
		$this->load->view('admin/v_group_post', $data);
	}

	function group_save(){
		$id = $this->input->post('id');
		$nama = $this->input->post('nama');
		$task = $this->input->post('task');
		$data = array(
			'group_name'=>$nama
		);
		$params = array(
			'id'=>$id,
			'data'=>$data,
			'task'=>$task
		);
		$result = $this->m_group->group_save($params);
		echo $result;
	}

	function group_list(){
		$query = $this->input->get('query');
		$pagenum = @$_GET['pagenum'];
		$pagesize = @$_GET['pagesize'];
		$start = $pagenum * $pagesize;
		$end = $start + $pagesize;

		$result=$this->m_group->group_list($query, $start, $end);
		echo $result;

	}


	function group_delete(){
		$id = $this->input->post('id');
		$id = is_numeric($id) ? $id : $id;
		$result = $this->m_group->group_delete($id);
		echo $result;
	}

	function group_search(){

	}

	function group_update(){

	}

	function group_create(){

	}

}
?>
